package com.qili.controller;

import com.qili.core.shiro.Principal;
import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.entity.base.BaseCompanyOwner;
import com.qili.entity.base.BaseDict;
import com.qili.entity.jc.dto.JcProjectDTO;
import com.qili.entity.search.BaseGreenRole;
import com.qili.entity.search.dto.BaseBigGreenRoleDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectDTO;
import com.qili.entity.sys.SysRegion;
import com.qili.entity.sys.SysRole;
import com.qili.entity.sys.dto.SysUserDTO;
import com.qili.entity.zx.dto.ZxProjectDTO;
import com.qili.mapper.jc.JcProjectMapper;
import com.qili.mapper.supervisor.SupervisorProjectMapper;
import com.qili.mapper.sys.SysRoleMapper;
import com.qili.mapper.sys.SysUserMapper;
import com.qili.mapper.zx.ZxProjectMapper;
import com.qili.service.SysUserService;
import com.qili.service.base.BaseCompanyOwnerService;
import com.qili.service.base.BaseDictService;
import com.qili.service.search.BaseGreenRoleService;
import com.qili.service.supplier.SupplierProjectManagerService;
import com.qili.service.sys.RoleUserService;
import com.qili.service.sys.SysRegionService;
import com.qili.util.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author zhaoyongke
 * @date 2021/6/1
 * @description 大屏展示
 */

@RequestMapping("/search/BigScreen")
@Controller
public class BigScreenController {

    @Autowired
    BaseDictService baseDictService;
    @Autowired
    BaseCompanyOwnerService baseCompanyOwnerService;
    @Autowired
    SysRegionService sysRegionService;
    @Autowired
    SupervisorProjectMapper supervisorProjectMapper;
    @Autowired
    ZxProjectMapper zxProjectMapper;
    @Autowired
    JcProjectMapper jcProjectMapper;
    @Autowired
    SysUserMapper sysUserMapper;

    @Autowired
    RoleUserService roleUserService;
    @Autowired
    SysRoleMapper sysRoleMapper;

    @Autowired
    BaseGreenRoleService baseGreenRoleService;

    @Autowired
    SupplierProjectManagerService supplierProjectManagerService;

    @Autowired
    SysUserService userService;

    // 大屏展示
    @GetMapping("index")
    public String BestPracticeIndex(Model model) {

        // 項目签单
        Boolean qdshow = userService.isHasPermission("zn:tj:qd");

        model.addAttribute("qdshow",qdshow?"1":"0");
        // 项目进度
        Boolean jdshow = userService.isHasPermission("zn:tj:jd");
        model.addAttribute("jdshow",jdshow?"1":"0");

        // 人员
        Boolean ryshow = userService.isHasPermission("zn:tj:ry");
        model.addAttribute("ryshow",ryshow?"1":"0");

        // 公司合同额
        Boolean gshteshow = userService.isHasPermission("zn:tj:gshte");
        model.addAttribute("gshteshow",gshteshow?"1":"0");

        // 总部合同额
        Boolean zbhteshow = userService.isHasPermission("zn:tj:zbhte");
        model.addAttribute("zbhteshow",zbhteshow?"1":"0");
        // 项目分部
        Boolean xmfbshow = userService.isHasPermission("zn:tj:fb");

        model.addAttribute("xmfbshow",xmfbshow?"1":"0");
        // 合同额 对比
        Boolean htedbshow = userService.isHasPermission("zn:tj:htedb");

        model.addAttribute("htedbshow",htedbshow?"1":"0");

        // 判断当前用户角色 是否有大屏演示角色
        boolean ysrole = Principal.hasRole("ysperson");
        if (ysrole) {
            model.addAttribute("zs", "0");
        } else {
            // 正式数据
            model.addAttribute("zs", "1");
        }
        return "/decision/BigScreen/bigScreenIndex";
    }

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description: 演示角色---大屏配置账号
     * @Date:9:40 2021/6/15
     */
    @GetMapping("ysRoleIndex")
    public String ysRoleIndex(Model model) {
        return "/decision/BigScreen/ysRoleIndex";
    }

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description: 添加角色
     * @Date:11:13 2021/6/15
     */
    @GetMapping("addBigRole")
    @RequiresPermissions("drastically:add")
    public String addBigRole(Model model) {
        // 所有的角色
        List<SysRole> sysRoles = sysRoleMapper.selectAll();
        model.addAttribute("roles", sysRoles);
        List<BaseDict> dictByType = DictUtil.getDictByType(DictTypes.MK001);
        model.addAttribute("mklist", dictByType);

        List<BaseDict> dictByTypeyx = DictUtil.getDictByType(DictTypes.MKYX001);
        model.addAttribute("mkyxlist", dictByTypeyx);

        return "/decision/BigScreen/addBigRole";
    }

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:修改角色
     * @Date:14:07 2021/6/15
     */
    @GetMapping("editBigRole")
    @RequiresPermissions("drastically:edit")
    public String editBigRole(BaseBigGreenRoleDTO dto, Model model) {
        String basePzId = dto.getBasePzId();
        BaseGreenRole baseGreenRole = baseGreenRoleService.selectByPrimaryKey(basePzId);
        model.addAttribute("greenRole", baseGreenRole);

        List<SysRole> sysRoles = sysRoleMapper.selectAll();
        model.addAttribute("roles", sysRoles);
        List<BaseDict> dictByType = DictUtil.getDictByType(DictTypes.MK001);
        List<BaseDict> dictByTypeyx = DictUtil.getDictByType(DictTypes.MKYX001);
        model.addAttribute("mklist", dictByType);
        model.addAttribute("mkyxlist", dictByTypeyx);
        return "/decision/BigScreen/editBigRole";
    }


    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description: 添加
     * @Date:13:20 2021/6/15
     */
    @RequestMapping("/saveBigRole")
    @ResponseBody
    @RequiresPermissions("drastically:add")
    public JsonUtil saveBigRole(BaseBigGreenRoleDTO dto) {
        try {
            JsonUtil re = new JsonUtil();
            BaseGreenRole baseBigGreenRole = new BaseGreenRole();
            BeanUtil.copyNotNullBean(dto, baseBigGreenRole);
            baseGreenRoleService.insertSelective(baseBigGreenRole);
            re.setFlag(true);
            re.setMsg("操作成功");
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JsonUtil.error("操作失败:" + e.getMessage());
        }
    }

    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description: 修改
     * @Date:13:20 2021/6/15
     */
    @RequestMapping("/updateBigRole")
    @ResponseBody
    @RequiresPermissions("drastically:edit")
    public JsonUtil updateBigRole(BaseBigGreenRoleDTO dto) {
        try {
            JsonUtil re = new JsonUtil();
            BaseGreenRole baseBigGreenRole = baseGreenRoleService.selectByPrimaryKey(dto.getBasePzId());
            BeanUtil.copyNotNullBean(dto, baseBigGreenRole);
            baseGreenRoleService.updateByPrimaryKey(baseBigGreenRole);
            re.setFlag(true);
            re.setMsg("操作成功");
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JsonUtil.error("操作失败:" + e.getMessage());
        }
    }

    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description:删除成功
     * @Date:14:52 2021/6/15
     */
    @RequestMapping("/deleteBigRole")
    @ResponseBody
    @RequiresPermissions("drastically:delete")
    public JsonUtil deleteBigRole(BaseBigGreenRoleDTO dto) {
        try {
            JsonUtil re = new JsonUtil();
            baseGreenRoleService.deleteByPrimaryKey(dto.getBasePzId());
            re.setFlag(true);
            re.setMsg("操作成功");
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JsonUtil.error("操作失败:" + e.getMessage());
        }
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:14:37 2021/5/25
     */
    @GetMapping(value = "/selectBigRoleList")
    @ResponseBody
    public ReType selectBigRoleList(BaseBigGreenRoleDTO dto, Model model, String page, String limit) {

        ReType show = baseGreenRoleService.show(dto, Integer.valueOf(page), Integer.valueOf(limit));
        return show;
    }


    @ApiOperation(value = "/getData", httpMethod = "GET")
    @GetMapping(value = "/getData")
    @ResponseBody
    public JsonUtil getData(BaseBigGreenRoleDTO  dto,Model model) {
        JsonUtil jsonUtil = new JsonUtil();
        String projectTypeStr = dto.getProjectTypeStr();
        HashMap map = new HashMap();
        // 判断当前用户角色 是否有大屏演示角色
        boolean ysrole = Principal.hasRole("ysperson");
        List list = new ArrayList();
        if (ysrole) {
            // 演示数据
            list = ysDoData(projectTypeStr);
        } else {
            List<String> positons = doRolePo();
            // 正式数据
            list = zsDoData(positons,projectTypeStr);
        }

        jsonUtil.setFlag(true);
        jsonUtil.setData(list);
        return jsonUtil;

    }

    public List<String> doRolePo() {
        List list = new ArrayList();
        String positon1 = "";
        // 位置2 对应的模块
        String positon2 = "";
        String positon3 = "";
        String positon4 = "";
        String positon5 = "";
        String positon6 = "";
        // 查询配置的角色位置信息
        BaseBigGreenRoleDTO dto = new BaseBigGreenRoleDTO();
        dto.setUserId(CommonUtil.getUserId());
        List<BaseBigGreenRoleDTO> dtolist = baseGreenRoleService.selectListRoleBigGreen(dto);
        if (dtolist.size() > 0) {
            if (dtolist.size() == 1) {
                positon1 = dtolist.get(0).getData1();
                positon2 = dtolist.get(0).getData2();
                positon3 = dtolist.get(0).getData3();
                positon4 = dtolist.get(0).getData4();
                positon5 = dtolist.get(0).getData5();
                positon6 = dtolist.get(0).getData6();
            } else {
                HashMap positionMap = new HashMap();
                HashMap<String, String> positionMapCheck = new HashMap<String, String>();
                for (int i = 0; i < dtolist.size(); i++) {
                    BaseBigGreenRoleDTO baseBigGreenRoleDTO = dtolist.get(i);
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData1())) {
                        String  str= baseBigGreenRoleDTO.getData1() + "," + baseBigGreenRoleDTO.getDataLv1();
                        String po_str = doRolePostion(positionMap, i, str, "l1", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon1 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData2())) {
                        String  str= baseBigGreenRoleDTO.getData2() + "," + baseBigGreenRoleDTO.getDataLv2();
                        String po_str = doRolePostion(positionMap, i, str, "l2", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon2 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData3())) {
                        String  str= baseBigGreenRoleDTO.getData3() + "," + baseBigGreenRoleDTO.getDataLv3();
                        String po_str = doRolePostion(positionMap, i, str, "l3", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon3 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData4())) {
                        String  str= baseBigGreenRoleDTO.getData4() + "," + baseBigGreenRoleDTO.getDataLv4();
                        String po_str = doRolePostion(positionMap, i, str, "l4", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon4 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData5())) {
                        String  str= baseBigGreenRoleDTO.getData5() + "," + baseBigGreenRoleDTO.getDataLv5();
                        String po_str = doRolePostion(positionMap, i, str, "l5", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon5 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }
                    if (StringUtil.isNotBlank(baseBigGreenRoleDTO.getData6())) {
                        String  str= baseBigGreenRoleDTO.getData6() + "," + baseBigGreenRoleDTO.getDataLv6();
                        String po_str = doRolePostion(positionMap, i, str, "l6", positionMapCheck);
                        if (StringUtil.isNotBlank(po_str)) {
                            positon6 = po_str;
                            positionMapCheck.put(po_str, "11");
                        }
                    }


                }
            }


        } else {
            // 走默认位置
            positon1="001";
            positon2="002";
            positon3="003";
            positon4="004";
            positon5="005";
            positon6="006";
        }
        list.add(positon1);
        list.add(positon2);
        list.add(positon3);
        list.add(positon4);
        list.add(positon5);
        list.add(positon6);
        return list;
    }




    /**
     * @param positionMap
     * @param i
     * @param str
     * @param key
     * @Author:zhaoyongke
     * @Description:
     * @Date:15:49 2021/6/3
     */
    public String doRolePostion(HashMap<String, String> positionMap, int i, String str, String key, HashMap<String, String> checkMap) {
        String positon1 = "";
        if (StringUtil.isNotBlank(str)) {
            String[] split = str.split(",");
            if (i == 0) {
                positon1 = split[0];
                positionMap.put(key, str);
            } else {
                // 获取之前存放的map 数据
                String postr = positionMap.get(key);
                String[] splitpo = postr.split(",");
                String old_level = "";
                String curr_level = "";
                if (splitpo.length > 1) {
                    old_level = splitpo[1];
                }
                // 当前的优先级别
                if (split.length > 1) {
                    curr_level = split[1];
                }
                if (StringUtil.isNotBlank(old_level) && StringUtil.isNotBlank(curr_level)) {
                    if (Integer.valueOf(curr_level) < Integer.valueOf(old_level) && checkMap.get(str) == null) {
                        positon1 = split[0];
                        positionMap.put(key, str);
                    }
                }
            }
        }
        return positon1;
    }


    /**
     * @Author:zhaoyongke
     * @Description: 演示数据库准备
     * @Date:9:56 2021/6/3
     */
    public List ysDoData(String projectTypeStr) {
        List list = new ArrayList();
        HashMap map = new HashMap();
        // 演示签单数据
        List<HashMap> qilist = ys_QdData();
        map.put("qd", qilist);
        // 进度
        List list_pro = ys_JdData();
        map.put("jd", list_pro);
        //人员情况
        List ryqklist = ys_RyqkData();
        map.put("ryqk", ryqklist);
        //公司合同额
        List gshtelist = ys_GshteData();
        map.put("gshte", gshtelist);
        //总部合同额
        List zbhtelist = ys_ZbhteData();
        map.put("zbhte", zbhtelist);
        //合同额对比
        List htedblist = ys_HtedbData();
        System.out.println("4545454");
        System.out.println(htedblist);
        System.out.println("909090");
        map.put("htedb", htedblist);
        //项目金额和数量
        List xmlist = ys_XmData();
        map.put("xm", xmlist);
        //项目分布
        List xmfblist = ys_XmfbData(projectTypeStr );
        map.put("xmfb", xmfblist);
        list.add(map);
        return list;
    }


    public  List<HashMap>  getDataListAfter (List<HashMap> qilist,String  projectTypeStr ){
        List<HashMap> qilistafter=new ArrayList<>();
        if(StringUtils.isNotBlank(projectTypeStr) ){
            if(qilist!=null  &&  qilist.size()>0 ){
                for (int i = 0; i <qilist.size() ; i++) {
                    HashMap mapi = qilist.get(i);
                    if(i==0){
                        // num1 num2  num3
                        if(projectTypeStr.indexOf("001")<0){
                            mapi.remove("num1");
                        }
                        if(projectTypeStr.indexOf("002")<0){
                            mapi.remove("num2");
                        }
                        if(projectTypeStr.indexOf("003")<0){
                            mapi.remove("num3");
                        }

                    }else if(i==1){
                        // name1  name2  name3
                        if(projectTypeStr.indexOf("001")<0){
                            mapi.remove("name1");
                        }
                        if(projectTypeStr.indexOf("002")<0){
                            mapi.remove("name2");
                        }
                        if(projectTypeStr.indexOf("003")<0){
                            mapi.remove("name3");
                        }

                    }
                    qilistafter.add(mapi);

                }
            }
            return  qilistafter;
        }else{
            return qilist;
        }

    }
    /**
     * @Author:zhangxiaopeng
     * @Description: 正式数据
     * @Date:9:56 2021/6/5
     */
    public List zsDoData(List<String> positons,String projectTypeStr) {
        List list = new ArrayList();
        HashMap map = new HashMap();
        // 签单数据
        List qilist = zs_QdData(positons);
        map.put("qd", qilist);
        // 进度
        List list_pro = zs_JdData(positons);
        map.put("jd", list_pro);
        //人员情况
        List ryqklist = zs_RyqkData(positons);
        map.put("ryqk", ryqklist);
        //公司合同额
        List gshtelist = zs_GshteData(positons);
        map.put("gshte", gshtelist);
        //总部合同额
        List zbhtelist = zs_ZbhteData(positons);
        map.put("zbhte", zbhtelist);
        //合同额对比
        List htedblist = zs_HtedbData(positons);
        map.put("htedb", htedblist);
        //项目金额和数量
        List xmlist = zs_XmData();
        map.put("xm", xmlist);
        //项目分布
        List xmfblist = zs_XmfbData(projectTypeStr);
        map.put("xmfb", xmfblist);
        list.add(map);
        return list;
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 演示签单数据
     * @Date:11:12 2021/6/3
     */
    public List ys_QdData() {
        List<BaseDict> dictByTypeQd = DictUtil.getDictByType(DictTypes.XMQDMK001);
        BaseDict baseDict = dictByTypeQd.get(0);
        List listChild = new ArrayList();
        HashMap mapChild = new HashMap();
        mapChild.put("num1", baseDict.getBadtLevel1());
        mapChild.put("num2", baseDict.getBadtLevel2());
        mapChild.put("num3", baseDict.getBadtLevel3());
        HashMap mapChild2 = new HashMap();
        mapChild2.put("name1", "监理");
        mapChild2.put("name2", "咨询");
        mapChild2.put("name3", "检测");
        Map<String, String> mapnum = sortHashMap(mapChild);
        listChild.add(mapnum);
        Map<String, String> mapname = sortHashMap(mapChild2);
        listChild.add(mapname);
        // 获取模块展示的位置
        List poByCode = new ArrayList();
        poByCode.add(0);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        listChild.add(mapChild3);
        return listChild;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式签单数据
     * @Date:11:12 2021/6/5
     */
    public List zs_QdData(List<String> positons) {
        List listChild = new ArrayList();
        Map map = new HashMap();
        //查询字典中配置的时间段
        List<BaseDict> baseDicts = selectBaseDict("QDSJD001");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.getCurrentDateTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (BaseDict base : baseDicts) {
            if ("1".equals(base.getBadtGroupid())) {
                if ("月".equals(base.getBadtLevel2())) {
                    calendar.add(Calendar.MONTH, -(Integer.parseInt(base.getBadtLevel1())));
                } else if ("年".equals(base.getBadtLevel2())) {
                    calendar.add(Calendar.YEAR, -(Integer.parseInt(base.getBadtLevel1())));
                }
                map.put("start", sdf.format(calendar.getTime()));
                map.put("end", DateUtil.getCurrentYearMonthDay());
            }
        }
        int jlnum = 0;
        int zxnum = 0;
        int jcnum = 0;
        if (map.size() > 0) {
            map.put("status", "004");
            map.put("type","001");
            jlnum = supervisorProjectMapper.selectSigning(map);
            map.remove("type");
            map.put("type","002");
            zxnum = zxProjectMapper.selectSigning(map);
            map.remove("type");
            map.put("type","003");
            jcnum = jcProjectMapper.selectSigning(map);
        }
        HashMap mapChild = new HashMap();
        mapChild.put("num1", jlnum);
        mapChild.put("num2", zxnum);
        mapChild.put("num3", jcnum);
        HashMap mapChild2 = new HashMap();
        mapChild2.put("name1", "监理");
        mapChild2.put("name2", "咨询");
        mapChild2.put("name3", "检测");
        Map<String, String> mapnum = sortHashMap(mapChild);
        listChild.add(mapnum);
        Map<String, String> mapname = sortHashMap(mapChild2);
        listChild.add(mapname);
        // 获取模块展示的位置
        List poByCode = getPoByCode("001", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        listChild.add(mapChild3);
        return listChild;
    }

    public List getPoByCode(String code, List<String> positons) {
        ArrayList list = new ArrayList();
        for (int i = 0; i < positons.size(); i++) {
            String s = positons.get(i);
            if (code.equals(s)) {
                list.add(i);
            }
        }
        return list;
    }

    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 演示进度数据
     * @Date:11:12 2021/6/3
     */
    public List ys_JdData() {
        List<BaseDict> dictByTypeQd = DictUtil.getDictByType(DictTypes.XMJDMK001);
        BaseDict baseDict = dictByTypeQd.get(0);
        String data1 = baseDict.getBadtLevel1();
        String data2 = baseDict.getBadtLevel2();
        String data3 = baseDict.getBadtLevel3();
        String data4 = baseDict.getBadtLevel4();
        String data5 = baseDict.getBadtLevel5();
        String data6 = baseDict.getBadtLevel6();
        String data7 = baseDict.getBadtLevel7();
        List listChild = new ArrayList();
        HashMap mapChildNum = new HashMap();
        HashMap mapChildName = new HashMap();
        int num = 1;

        if (StringUtil.isNotBlank(data1)) {
            String[] split = data1.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data2)) {
            String[] split = data2.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data3)) {
            String[] split = data3.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data4)) {
            String[] split = data4.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data5)) {
            String[] split = data5.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data6)) {
            String[] split = data6.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        if (StringUtil.isNotBlank(data7)) {
            String[] split = data7.split(",");
            mapChildNum.put("num" + num, split[1]);
            mapChildName.put("name" + num, split[0]);
            num++;
        }
        Map<String, String> mapnum = sortHashMap(mapChildNum);
        listChild.add(mapnum);
        Map<String, String> mapname = sortHashMap(mapChildName);
        listChild.add(mapname);
        // 位置
        List poByCode = new ArrayList();
        poByCode.add(1);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        listChild.add(mapChild3);
        return listChild;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式进度数据
     * @Date:11:12 2021/6/5
     */
    public List zs_JdData(List<String> positons) {
        List listChild = new ArrayList();
        Map map = new HashMap();
        map.put("status", "000");
        map.put("projectNum", 7);
        List<SupervisorProjectDTO> list = supervisorProjectMapper.selectSupervisorList(map);
        HashMap mapChildNum = new HashMap();
        HashMap mapChildName = new HashMap();
        int num = 1;
        for (SupervisorProjectDTO dto : list) {
            mapChildNum.put("num" + num, dto.getProgress());
            mapChildName.put("name" + num, dto.getProjectName());
            num++;
        }
        Map<String, String> mapnum = sortHashMap(mapChildNum);
        listChild.add(mapnum);
        Map<String, String> mapname = sortHashMap(mapChildName);
        listChild.add(mapname);

        // 获取模块展示的位置
        List poByCode = getPoByCode("002", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        listChild.add(mapChild3);
        return listChild;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示人员情况数据
     * @Date:11:12 2021/6/3
     */
    public List ys_RyqkData() {
        List list = new ArrayList();
        List<BaseDict> baseDicts = selectBaseDict("RYQKMK001");
        if (baseDicts != null && baseDicts.size() > 0) {
            for (int i = 0; i < baseDicts.size(); i++) {
                List<Map> listMap = new ArrayList<>();
                Map map1 = new HashMap();
                Map map2 = new HashMap();
                Map map3 = new HashMap();
                if (i == 0) {
                    map1.put("name", "监理");
                    map1.put("value", baseDicts.get(i).getBadtLevel1());
                    map2.put("name", "咨询");
                    map2.put("value", baseDicts.get(i).getBadtLevel2());
                    map3.put("name", "检测");
                    map3.put("value", baseDicts.get(i).getBadtLevel3());
                } else if (i == 1) {
                    map1.put("name", "25及以下");
                    map1.put("value", baseDicts.get(i).getBadtLevel1());
                    map2.put("name", "26-40");
                    map2.put("value", baseDicts.get(i).getBadtLevel2());
                    map3.put("name", "41及以上");
                    map3.put("value", baseDicts.get(i).getBadtLevel3());
                } else if (i == 2) {
                    map3.put("name", "研究生及以上");
                    map3.put("value", baseDicts.get(i).getBadtLevel3());
                    map2.put("name", "本科");
                    map2.put("value", baseDicts.get(i).getBadtLevel2());
                    map1.put("name", "大专及以下");
                    map1.put("value", baseDicts.get(i).getBadtLevel1());
                }
                listMap.add(map1);
                listMap.add(map2);
                listMap.add(map3);
                list.add(listMap);
            }

        }

        // 获取模块展示的位置
        List poByCode = new ArrayList();
        poByCode.add(2);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式人员情况数据
     * @Date:11:12 2021/6/5
     */
    public List zs_RyqkData(List<String> positons) {
        List list = new ArrayList();
        Map map = new HashMap();
        //业务类型
        map.put("ywlx", "ywlx");
        List<SysUserDTO> userYw = sysUserMapper.selectUserStats(map);
        if (userYw != null && userYw.size() > 0) {
            List<Map> listMap = new ArrayList<>();
            for (int i = 0; i < userYw.size(); i++) {
                Map map1 = new HashMap();
                map1.put("name", userYw.get(i).getName());
                map1.put("value", userYw.get(i).getValue());
                listMap.add(map1);
            }
            list.add(listMap);
        }
        map.remove("ywlx");
        //统计年龄
        map.put("nl", "nl");
        List<SysUserDTO> userNl = sysUserMapper.selectUserStats(map);
        if (userNl != null && userNl.size() > 0) {
            List<Map> listMap = new ArrayList<>();
            for (int i = 0; i < userNl.size(); i++) {
                Map map1 = new HashMap();
                map1.put("name", userNl.get(i).getName());
                map1.put("value", userNl.get(i).getValue());
                listMap.add(map1);
            }
            list.add(listMap);
        }
        map.remove("nl");
        //统计学历
        map.put("xl", "xl");
        List<SysUserDTO> userXl = sysUserMapper.selectUserStats(map);
        if (userXl != null && userXl.size() > 0) {
            List<Map> listMap = new ArrayList<>();
            for (int i = 0; i < userXl.size(); i++) {
                Map map1 = new HashMap();
                map1.put("name", userXl.get(i).getName());
                map1.put("value", userXl.get(i).getValue());
                listMap.add(map1);
            }
            list.add(listMap);
        }

        // 获取模块展示的位置
        List poByCode = getPoByCode("003", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);

        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示公司合同额数据
     * @Date:11:12 2021/6/3
     */
    public List ys_GshteData() {
        List list = new ArrayList();
        List<BaseDict> baseDicts = selectBaseDict("GSHTEMK");
        Map jlmap = new HashMap();
        Map zxmap = new HashMap();
        Map jcmap = new HashMap();
        String[] name = new String[baseDicts.size()];
        if (baseDicts != null && baseDicts.size() > 0) {
            String[] jlamount = new String[baseDicts.size()];
            String[] zxamount = new String[baseDicts.size()];
            String[] jcamount = new String[baseDicts.size()];
            for (int i = 0; i < baseDicts.size(); i++) {
                name[i] = baseDicts.get(i).getBadtName();
                jlamount[i] = baseDicts.get(i).getBadtLevel1();
                zxamount[i] = baseDicts.get(i).getBadtLevel2();
                jcamount[i] = baseDicts.get(i).getBadtLevel3();
            }
            jlmap.put("name", "监理");
            jlmap.put("type", "line");
            jlmap.put("smooth", true);
            jlmap.put("data", jlamount);
            zxmap.put("name", "咨询");
            zxmap.put("type", "line");
            zxmap.put("smooth", true);
            zxmap.put("data", zxamount);
            jcmap.put("name", "检测");
            jcmap.put("type", "line");
            jcmap.put("smooth", true);
            jcmap.put("data", jcamount);

        }
        list.add(name);
        list.add(jlmap);
        list.add(zxmap);
        list.add(jcmap);
        // 获取模块展示的位置
        List poByCode = new ArrayList();
        poByCode.add(3);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式公司合同额数据
     * @Date:11:12 2021/6/3
     */
    public List zs_GshteData(List<String> positons) {
        List list = new ArrayList();
        Map map = new HashMap();
        //查询字典中配置的时间段
        List<BaseDict> baseDicts = selectBaseDict("GSSJD001");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.getCurrentDateTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> timeList = new ArrayList<>();
        try {
            for (BaseDict base : baseDicts) {
                if ("1".equals(base.getBadtGroupid())) {
                    if ("月".equals(base.getBadtLevel2())) {
                        calendar.add(Calendar.MONTH, -(Integer.parseInt(base.getBadtLevel1())));
                    } else if ("年".equals(base.getBadtLevel2())) {
                        calendar.add(Calendar.YEAR, -(Integer.parseInt(base.getBadtLevel1())));
                    }
                    timeList = getMonthBetween(sdf.format(calendar.getTime()), DateUtil.getCurrentYearMonthDay());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map jlmap = new HashMap();
        Map jcmap = new HashMap();
        Map zxmap = new HashMap();
        //横坐标的月份
        String[] name = null;
        String[] jlamount = null;
        String[] jcamount = null;
        String[] zxamount = null;
        if (timeList != null && timeList.size() > 0) {
            name = new String[timeList.size()];
            jlamount = new String[timeList.size()];
            zxamount = new String[timeList.size()];
            jcamount = new String[timeList.size()];
            for (int i = 0; i < timeList.size(); i++) {
                //月份
                name[i] = timeList.get(i);
                //监理项目对应月份的金额
                map.put("time", timeList.get(i));
                List<SupervisorProjectDTO> listJl = supervisorProjectMapper.selectAmounts(map);
                if (listJl != null && listJl.size() > 0) {
                    jlamount[i] = listJl.get(0).getHtMoney();
                }
                List<JcProjectDTO> listJc = jcProjectMapper.selectAmounts(map);
                if (listJc != null && listJc.size() > 0) {
                    jcamount[i] = listJc.get(0).getHtMoney();
                }
                List<ZxProjectDTO> listZx = zxProjectMapper.selectAmounts(map);
                if (listZx != null && listZx.size() > 0) {
                    zxamount[i] = listZx.get(0).getHtMoney();
                }
            }
            jlmap.put("name", "监理");
            jlmap.put("type", "line");
            jlmap.put("smooth", true);
            jlmap.put("data", jlamount);

            jcmap.put("name", "检测");
            jcmap.put("type", "line");
            jcmap.put("smooth", true);
            jcmap.put("data", jcamount);

            zxmap.put("name", "咨询");
            zxmap.put("type", "line");
            zxmap.put("smooth", true);
            zxmap.put("data", zxamount);
        }
        //先添加月份 在是监理、咨询、检测
        list.add(name);
        list.add(jlmap);
        list.add(zxmap);
        list.add(jcmap);
        // 获取模块展示的位置
        List poByCode = getPoByCode("004", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);

        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示总部合同额数据
     * @Date:11:12 2021/6/3
     */
    public List ys_ZbhteData() {
        List list = new ArrayList();
        List<BaseDict> baseDicts = selectBaseDict("ZBHTEMK");
        String[] name = new String[3];
        String[] number = new String[3];
        if (baseDicts != null && baseDicts.size() > 0) {
            name[0] = "监理";
            name[1] = "咨询";
            name[2] = "检测";
            number[0] = baseDicts.get(0).getBadtLevel1();
            number[1] = baseDicts.get(0).getBadtLevel2();
            number[2] = baseDicts.get(0).getBadtLevel3();
        }
        list.add(name);
        list.add(number);

        // 获取模块展示的位置
        List poByCode = new ArrayList();
        poByCode.add(4);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);

        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式总部合同额数据
     * @Date:11:12 2021/6/5
     */
    public List zs_ZbhteData(List<String> positons) {
        List list = new ArrayList();
        Map map = new HashMap();
        //查询字典中配置的时间段
        List<BaseDict> baseDicts = selectBaseDict("ZBSJD001");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.getCurrentDateTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (BaseDict base : baseDicts) {
            if ("1".equals(base.getBadtGroupid())) {
                if ("月".equals(base.getBadtLevel2())) {
                    calendar.add(Calendar.MONTH, -(Integer.parseInt(base.getBadtLevel1())));
                } else if ("年".equals(base.getBadtLevel2())) {
                    calendar.add(Calendar.YEAR, -(Integer.parseInt(base.getBadtLevel1())));
                }
                map.put("start", sdf.format(calendar.getTime()));
                map.put("end", DateUtil.getCurrentYearMonthDay());
            }
        }
        //项目归属为总部
        map.put("company", "1564895");
        String[] name = new String[3];
        String[] number = new String[3];
        //监理
        SupervisorProjectDTO listJl = supervisorProjectMapper.selectHeadquartersAmount(map);
        ZxProjectDTO listZx = zxProjectMapper.selectHeadquartersAmount(map);
        JcProjectDTO listJc = jcProjectMapper.selectHeadquartersAmount(map);
        name[0] = "监理";
        name[1] = "咨询";
        name[2] = "检测";
        number[0] = listJl.getHtMoney();
        number[1] = listZx.getHtMoney();
        number[2] = listJc.getHtMoney();
        list.add(name);
        list.add(number);
        // 获取模块展示的位置
        List poByCode = getPoByCode("005", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示合同额对比数据
     * @Date:11:12 2021/6/3
     */
    public List ys_HtedbData() {
        List list = new ArrayList();
        List<BaseDict> baseDicts = selectBaseDict("HTEDBMK");
        if (baseDicts != null && baseDicts.size() > 0) {
            String[] name = new String[baseDicts.size()];
            String[] number = new String[baseDicts.size()];
            for (int i = 0; i < baseDicts.size(); i++) {
                name[i] = baseDicts.get(i).getBadtName();
                number[i] = baseDicts.get(i).getBadtLevel1();
            }
            list.add(name);
            list.add(number);
        }
        // 获取模块展示的位置
        List poByCode = new ArrayList();
        poByCode.add(5);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式合同额对比数据
     * @Date:11:12 2021/6/3
     */
    public List zs_HtedbData(List<String> positons) {
        List list = new ArrayList();
        Map map = new HashMap();
        /*项目归属*/
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        map.put("year", DateUtil.getCurrentYear());
//        StringJoiner join=new StringJoiner(",");
//        for (int i = 0; i < AlstCompany.size(); i++) {
//            if(!"1564895".equals(AlstCompany.get(i).getBcId())) {
//                join.add(AlstCompany.get(i).getBcId());
//            }
//        }
//        map.put("company", list(join.toString()));
//        List<SupervisorProjectDTO> dto = supervisorProjectMapper.selectAmountContrastDP(map);

        /**
         * 2022年7月18日15:08:32  添加检测和咨询合同对比额
         * 取 监理 检测 咨询 总和
         */
        List<Map<String, Object>> objMaps = new ArrayList<>();

        List<Map<String, Object>> zb = supervisorProjectMapper.selectAmountContrastDPTotal("1564895",DateUtil.getCurrentYear());

        List<BaseCompanyOwner> baseCompanyOwners = baseCompanyOwnerService.selectAll();
        for (BaseCompanyOwner baseCompanyOwner : baseCompanyOwners) {
            String bcId = baseCompanyOwner.getBcId();
            if ("1564895".equals(bcId)){
                continue;
            }
            // 查询
            List<Map<String, Object>> maps = supervisorProjectMapper.selectAmountContrastDPTotal(bcId,DateUtil.getCurrentYear());
            objMaps.add(maps.get(0));
        }

        Collections.sort(objMaps, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double value1 = (Double) o1.get("total");

                Double value2 = (Double) o2.get("total");
                // 降序
                return value2.compareTo(value1);
            }
        });

        String[] name = new String[7];
        String[] number = new String[7];
//        for(int j=0;j<dto.size();j++){
//            name[j] = dto.get(j).getProjectOwner();
//            number[j] = dto.get(j).getHtMoney();
//        }

        name[0] = zb.get(0).get("projectOwner").toString();
        number[0] = zb.get(0).get("total").toString();
        for(int k = 1;k < 7; k++){
            name[k] = objMaps.get(k).get("projectOwner").toString();
            number[k] = objMaps.get(k).get("total").toString();
        }
        list.add(name);
        list.add(number);
        // 获取模块展示的位置
        List poByCode = getPoByCode("006", positons);
        HashMap mapChild3 = new HashMap();
        mapChild3.put("po", poByCode);
        list.add(mapChild3);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示项目金额和数量
     * @Date:11:12 2021/6/3
     */
    public List ys_XmData() {
        List list = new ArrayList();
        HashMap map = new HashMap();
        List<BaseDict> baseDicts = selectBaseDict("XMFBMK001");
        if (baseDicts != null && baseDicts.size() > 0) {
            for (int i = 0; i < baseDicts.size(); i++) {
                if ("001".equals(baseDicts.get(i).getBadtCode())) {
                    map.put("zxm", baseDicts.get(i).getBadtLevel1());
                    map.put("jlxm", baseDicts.get(i).getBadtLevel2());
                    map.put("zxxm", baseDicts.get(i).getBadtLevel3());
                    map.put("jcxm", baseDicts.get(i).getBadtLevel4());
                } else if ("002".equals(baseDicts.get(i).getBadtCode())) {
                    map.put("zhte", baseDicts.get(i).getBadtLevel1());
                    map.put("jlhte", baseDicts.get(i).getBadtLevel2());
                    map.put("zxhte", baseDicts.get(i).getBadtLevel3());
                    map.put("jchte", baseDicts.get(i).getBadtLevel4());
                }
            }
            list.add(map);
        }
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式项目金额和数量
     * @Date:11:12 2021/6/5
     */
    public List zs_XmData() {
        List list = new ArrayList();
        Map map = new HashMap();
        Map map1 = new HashMap();
        map1.put("year", DateUtil.getCurrentYear());
        //监理的项目数量和总金额
        SupervisorProjectDTO spd = supervisorProjectMapper.selectDistribution(map1);
        map.put("jlxm", spd.getNum());
        map.put("jlhte", spd.getHtMoney());
        //咨询
        ZxProjectDTO zxspd = zxProjectMapper.selectDistribution(map1);
        map.put("zxxm", zxspd.getNum());
        map.put("zxhte", zxspd.getHtMoney());
        //检测
        JcProjectDTO jcspd = jcProjectMapper.selectDistribution(map1);
        map.put("jcxm", jcspd.getNum());
        map.put("jchte", jcspd.getHtMoney());

        BigDecimal jlxm=new BigDecimal(spd.getNum());
        BigDecimal jcxm=new BigDecimal(zxspd.getNum());
        BigDecimal zxxm=new BigDecimal(jcspd.getNum());

        BigDecimal jlhte=new BigDecimal(spd.getHtMoney());
        BigDecimal jchte=new BigDecimal(zxspd.getHtMoney());
        BigDecimal zxhte=new BigDecimal(jcspd.getHtMoney());
        //总项目数和总金额   三种类型的相加
        map.put("zxm", (jlxm.add(jcxm).add(zxxm)).toString());
        map.put("zhte", (jlhte.add(jchte).add(zxhte)).toString());
        list.add(map);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 演示项目分布数据
     * @Date:11:12 2021/6/3
     */
    public List ys_XmfbData(String  projectTypeStr) {
        List list = new ArrayList();
        List<BaseDict> baseDicts = selectBaseDict("XMFBMK001");
        //查询分公司所在的地区标记小红旗
        List<Map> list_hq = new ArrayList<>();
        List<BaseCompanyOwner> listCom = baseCompanyOwnerService.selectAll();
        for (BaseCompanyOwner com : listCom) {
            if (StringUtils.isNotBlank(com.getRegion())) {
                Map map = new HashMap();
                map.put("name", com.getRegion());
                map.put("value", 100);
                list_hq.add(map);
            }
        }
        list.add(list_hq);
        //查询所有省份
        List<Map> listMap = new ArrayList<>();
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        for (int i = 0; i < provincelist.size(); i++) {
            String name = province(provincelist.get(i).getName());
            Map map = new HashMap();
            //查询配置的省份金额和数量
            for (int j = 0; j < baseDicts.size(); j++) {
                //前两条配置的不是地图的数量金额
                if (!"001".equals(baseDicts.get(j).getBadtCode()) && !"002".equals(baseDicts.get(j).getBadtCode())) {
                    //配置的地区名匹配
                    if (name.equals(baseDicts.get(j).getBadtName())) {
                        //根据id查询省份下的城市名
                        List<SysRegion> reg = region(provincelist.get(i).getId());
                        //判断有没有监理的项目
                        if (reg.size() > 3) {
                            if((StringUtils.isNotBlank(projectTypeStr) && projectTypeStr.indexOf("001")>-1) || StringUtils.isBlank(projectTypeStr) ){
                                if (Integer.parseInt(baseDicts.get(j).getBadtLevel3()) > 0) {
                                    Map jl = new HashMap();
                                    jl.put("name", province(reg.get(1).getName()));
                                    jl.put("value", 60);
                                    jl.put("color", "green");
                                    listMap.add(jl);
                                }
                            }

                            if((StringUtils.isNotBlank(projectTypeStr) && projectTypeStr.indexOf("002")>-1) || StringUtils.isBlank(projectTypeStr) ){
                                //判断有没有咨询的项目
                                if (Integer.parseInt(baseDicts.get(j).getBadtLevel5()) > 0) {
                                    Map zx = new HashMap();
                                    zx.put("name", province(reg.get(2).getName()));
                                    zx.put("value", 60);
                                    zx.put("color", "yellow");
                                    listMap.add(zx);
                                }
                            }

                            if((StringUtils.isNotBlank(projectTypeStr) && projectTypeStr.indexOf("003")>-1) || StringUtils.isBlank(projectTypeStr) ){
                                //判断有没有检测的项目
                                if (Integer.parseInt(baseDicts.get(j).getBadtLevel7()) > 0) {
                                    Map jc = new HashMap();
                                    jc.put("name", province(reg.get(3).getName()));
                                    jc.put("value", 60);
                                    jc.put("color", "red");
                                    listMap.add(jc);
                                }
                            }



                        }

                    }
                }
            }

            map.put("name", name);
            map.put("value", 1);
            listMap.add(map);
        }
        list.add(listMap);
        //项目个数和合同金额
        List<Map> list1 = new ArrayList<>();
        for (BaseDict base : baseDicts) {
            Map map = new HashMap();
            map.put("name", base.getBadtName());
            map.put("zsl", base.getBadtLevel1());
            map.put("zje", base.getBadtLevel2());
            map.put("jlsl", base.getBadtLevel3());
            map.put("jlje", base.getBadtLevel4());
            map.put("zxsl", base.getBadtLevel5());
            map.put("zxje", base.getBadtLevel6());
            map.put("jcsl", base.getBadtLevel7());
            map.put("jcje", base.getBadtLevel8());
            list1.add(map);
        }
        list.add(list1);
        return list;
    }

    /**
     * @param
     * @Author:zhangxiaopeng
     * @Description: 正式项目分布数据
     * @Date:11:12 2021/6/5
     */
    public List zs_XmfbData(String projectTypeStr) {
        List list = new ArrayList();
        //查询分公司所在的地区标记小红旗
        List<Map> list_hq = new ArrayList<>();
        List<BaseCompanyOwner> listCom = baseCompanyOwnerService.selectAll();
        for (BaseCompanyOwner com : listCom) {
            if (StringUtils.isNotBlank(com.getRegion())) {
                Map map = new HashMap();
                map.put("name", com.getRegion());
                map.put("value", 100);
                list_hq.add(map);
            }
        }
        list.add(list_hq);
        Map map1 = new HashMap();
        //查询所有省份
        List<Map> listMap = new ArrayList<>();
        //存放项目个数和合同金额
        List<Map> list1 = new ArrayList<>();
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        for (int i = 0; i < provincelist.size(); i++) {
            String name = province(provincelist.get(i).getName());
            Map map = new HashMap();
            map1.put("province", provincelist.get(i).getCode());
            //根据id查询省份下的城市名
            List<SysRegion> reg = region(provincelist.get(i).getId());
            //项目个数和合同金额
            BigDecimal zje = new BigDecimal("0.0");
            BigDecimal jlje = new BigDecimal("0.0");
            BigDecimal zxje = new BigDecimal("0.0");
            BigDecimal jcje = new BigDecimal("0.0");
            int zsl = 0;
            int jlsl = 0;
            int zxsl = 0;
            int jcsl = 0;
            //查询项目所在的城市
            List<SupervisorProjectDTO> cityList=supervisorProjectMapper.selectAllCity(map1);
            Boolean  jlfind=false;
            Boolean  zxfind=false;
            Boolean  jcfind=false;
            if(StringUtils.isNotBlank(projectTypeStr)){
                if(projectTypeStr.indexOf("001")>-1) {
                    jlfind=true;
                }
                if(projectTypeStr.indexOf("002")>-1) {
                    zxfind=true;
                }
                if(projectTypeStr.indexOf("003")>-1) {
                    jcfind=true;
                }
            }

            for(SupervisorProjectDTO city : cityList){
                Map allCity = new HashMap();
                String type = city.getType();
                if(StringUtils.isNotBlank(projectTypeStr)){
                    // 获取包含的类型
                    if(jlfind && !zxfind && !jcfind ){
                        //只包含监理
                        if("1".equals(type)){
                            addCityDataImage(allCity,city);
                        }
                    }else if(jcfind && !jlfind && !zxfind ){
                        //只包含检测
                        if("3".equals(type)){
                            addCityDataImage(allCity,city);
                        }
                    }else if(zxfind  && !jlfind  && !jcfind  ){
                        //只包含咨询
                        if("2".equals(type)){
                            addCityDataImage(allCity,city);
                        }
                    }else if(jlfind  && zxfind  && !jcfind ){
                        // 只有  监理 咨询
                        if("1".equals(type)   ||  "2".equals(type)  || "1,2".equals(type)  ){
                            addCityDataImage(allCity,city);
                        }
                    }else if(jlfind  && jcfind  && !zxfind ){
                        // 只有  监理 检测
                        if("1".equals(type)   ||  "3".equals(type)  || "1,3".equals(type)  ){
                            addCityDataImage(allCity,city);
                        }
                    }else if( jcfind  && zxfind   && !jlfind  ){
                        // 只有 咨询 检测
                        if("2".equals(type)   ||  "3".equals(type)  || "2,3".equals(type)  ){
                            addCityDataImage(allCity,city);
                        }
                    }else if( jcfind  && zxfind   && jlfind  ){
                        addCityDataImage(allCity,city);
                    }


                }else{
                    // 默認 查询所有类型
                    addCityDataImage(allCity,city);

                }

                listMap.add(allCity);
//
           }
            //监理
            SupervisorProjectDTO spd = supervisorProjectMapper.selectDistribution(map1);
            if (spd != null && !"".equals(spd)) {
                if (StringUtil.isNotBlank(spd.getProvince())) {
                    //判断有没有监理的项目
                    Map jl = new HashMap();
                    //根据省份查出来的城市
//                    if (reg != null && reg.size() > 3) {
//                        jl.put("name", province(reg.get(1).getName()));
//                        jl.put("value", 60);
//                        jl.put("color", "green");
//                        listMap.add(jl);
//                    }
                    //监理合同额
                    jlje = new BigDecimal(spd.getHtMoney());
                    zje = zje.add(jlje);
                    //监理项目数
                    jlsl = Integer.parseInt(spd.getNum());
                    zsl += jlsl;
                }
            }

            //咨询
            //判断有没有咨询的项目
            ZxProjectDTO zxspd = zxProjectMapper.selectDistribution(map1);
            if (zxspd != null && !"".equals(zxspd)) {
                if (StringUtil.isNotBlank(zxspd.getProvince())) {
                    //判断有没有监理的项目
                    Map zx=new HashMap();
                    //根据省份查出来的城市
//                    if (reg != null && reg.size() > 3) {
//                        zx.put("name", province(reg.get(2).getName()));
//                        zx.put("value", 60);
//                        zx.put("color", "yellow");
//                        listMap.add(zx);
//                    }
                    //咨询合同额
                    zxje = new BigDecimal(zxspd.getHtMoney());
                    zje = zje.add(zxje);
                    //咨询项目数
                    zxsl = Integer.parseInt(zxspd.getNum());
                    zsl += zxsl;
                }
            }

            //检测
            //判断有没有检测的项目
            JcProjectDTO jcspd = jcProjectMapper.selectDistribution(map1);
            if (jcspd != null && !"".equals(jcspd)) {
                if (StringUtil.isNotBlank(jcspd.getProvince())) {
                    //判断有没有监理的项目
                    Map jc=new HashMap();
                    //根据省份查出来的城市
//                    if (reg != null && reg.size() > 3) {
//                        jc.put("name", province(reg.get(3).getName()));
//                        jc.put("value", 60);
//                        jc.put("color", "red");
//                        listMap.add(jc);
//                    }
                    //检测合同额
                    jcje = new BigDecimal(jcspd.getHtMoney());
                    zje = zje.add(jcje);
                    //检测项目数
                    jcsl = Integer.parseInt(jcspd.getNum());
                    zsl += jcsl;
                }
            }


            map.put("name", name);
            map.put("value", 1);
            listMap.add(map);
            Map mapNum = new HashMap();
            mapNum.put("name", name);
            mapNum.put("zsl", zsl);
            mapNum.put("zje", zje);
            mapNum.put("jlsl", jlsl);
            mapNum.put("jlje", jlje);
            mapNum.put("zxsl", zxsl);
            mapNum.put("zxje", zxje);
            mapNum.put("jcsl", jcsl);
            mapNum.put("jcje", jcje);
            list1.add(mapNum);
        }
        list.add(listMap);
        list.add(list1);
        return list;
    }

    public  void   addCityDataImage(Map allCity,SupervisorProjectDTO  city){
        String cityname = province(city.getCityName());
        if("恩施".indexOf(cityname)>-1){
            cityname="恩施";
        }
        if("1,2,3".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("1,2".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("1,3".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("2,3".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("1".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("2".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }else if("3".equals(city.getType())){
            allCity.put("name",cityname);
            allCity.put("value",80);
            allCity.put("symbol","image://");
        }

    }

    //根据id查询城市数据
    public List<SysRegion> region(Long id) {
        //城市
        SysRegion sysRegion = new SysRegion();
        sysRegion.setParentId(id);
        return sysRegionService.select(sysRegion);
    }

    //去掉省份的后缀
    public String province(String name) {
        name = name.replace("省", "");
        name = name.replace("市", "");
        name = name.replace("自治区", "");
        name = name.replace("特别行政区", "");
        name = name.replace("回族", "");
        name = name.replace("维吾尔", "");
        name = name.replace("壮族", "");
        name = name.replace("城区", "");
        return name;
    }

    //传入编码查询字典数据
    public List<BaseDict> selectBaseDict(String code) {
        BaseDict dict = new BaseDict();
        dict.setBadtTypecode(code);
        return baseDictService.select(dict);
    }

    // 排序
    public static Map<String, String> sortHashMap(Map<String, String> map) {
        Map<String, String> sortedMap = new LinkedHashMap<String, String>();
        List<String> list = new ArrayList<String>();
        Iterator<String> item = map.keySet().iterator();
        while (item.hasNext()) {
            list.add(item.next());
        }
        Collections.sort(list);
        Iterator<String> item2 = list.iterator();
        while (item2.hasNext()) {
            String key = item2.next();
            sortedMap.put(key, map.get(key));
        }
        return sortedMap;
    }

    //传入两个日期 获取之间的时间年月
    public static List<String> getMonthBetween(String minDate, String maxDate) throws Exception {
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");// 格式化为年月
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf.parse(minDate));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);// 设置年月日，最少3个参数
        max.setTime(sdf.parse(maxDate));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max)) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }
    //逗号分割返回List
    public List<String> list(String name){
        List<String> list = new ArrayList<>();
        if(StringUtils.isNotBlank(name)) {
            String[] arr = name.split(",");
            for (int i = 0; i < arr.length; i++) {
                list.add(arr[i]);
            }
        }
        return list;
    }

}
